package com.yc.bank.dao;

import com.yc.bank.entity.Oprecord;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class OprecorDao {
    //1.insert 方法 ==》写账号流水
    //2.selectByAid  ==>查账号操作流水

    @Resource
    JdbcTemplate jdbcTemplate;
    public void insert(Oprecord oprecord){
        String sql = "insert into bank_oprecord values" +
                "(default,?,?,?,now(),?)";
        jdbcTemplate.update(sql,oprecord.getAid(),
                                oprecord.getOpmoney(),
                                oprecord.getCharge(),
                                oprecord.getRemark());
    }

    public List<Oprecord> selectByAid(String aid){
        String sql = "select * from bank_oprecord where aid = ";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Oprecord.class),aid);
    }
}
